#! /usr/bin/env python
# coding=utf-8
# ******************************************************************************
# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
# licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#     http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# Author: senlin
# Create: 2021-06-29
# ******************************************************************************/
import os
from src.libs.logger import logger
import yaml

curpath = os.path.dirname(os.path.realpath(__file__))

class YamlReadAndWrite(object):
    """
    Read and writ yaml
    """
    def __init__(self, yaml_file):
        """
        """
        self.yamlpath = yaml_file


    def read_yaml(self):
        """
        """
        if not os.path.isfile(self.yamlpath):
            logger.warning("not found the file: %s", self.yamlpath)
            return False
        with open(self.yamlpath, encoding='utf-8') as f:
            yaml_data = yaml.load(f, Loader=yaml.Loader)
            return yaml_data

    def write_yaml(self, record_data):
        """
        """
        with open(self.yamlpath, "w", encoding="utf-8") as f:
            yaml.dump(record_data, f)